<%--
	fileName      : personal_modify.jsp
	author        : KFZX-liukai
	createDate    : 2010-6-7  上午10:42:31
	lastModifier  : KFZX-liukai
	lastModifyDate: 2010-6-7  上午10:42:31
	description   : 个人信息设置
--%>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="ctp-tag" prefix="ctp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<title><ctp:label key="user_detail_modify"/></title>
		<ctp:include items="gridlayout,toolbar,borderlayout,panel,button,form,label,textfield,textarea,checkbox,validator,MESSAGE_EX,groupbox,image"/>
		<script type='text/javascript' kind='variant'>		  
		    //================================UI变量定义片段============================================================
			var ctpBorderlayout;//页面框架布局器
		    var ctpForm;//用户表单
		    var ctpToolbar;//工具条
		    var ctpGridlayout1;//布局器1
		    var ctpGridlayout2;//布局器2
		    var ctpGridlayout3;//布局器3
		    var ctpPanel;//Panel
		    var ctpGroupbox1;//Groupbox
		    var ctpGroupbox2;//Groupbox
		    var ctpId;//用户ID组件
			var ctpName;//用户名称组件
			var ctpDescription;//用户描述组件
			var ctpPhoneNo;//电话号码组件
			var ctpEmail;//电子邮件组件
			var ctpAddress;//地址组件
			var ctpPostcode;//邮政编码组件
			var ctpChangePassword;//用户修改密码组件
			var ctpOldPassword;//用户密码组件
			var ctpPassword;//用户密码组件
			var ctpPassword2;//重复输入密码组件
			var ctpImage;//图片组件

			var ctpPwdInfoPanel;//安全改造，密码控件页面的iframe载体
			var iframeSrc = '<ctp:url href="personal.flowc" flowActionName="password" />';//密码控件的所在页面url
		</script>
		<script type='text/javascript' kind='event'>
			//================================函数定义片段============================================================
			var language='<ctp:out name="sessCtx.Language" />';//获取当前语言环境
			var widthPassword = language.toString().toLowerCase().startsWith("zh") == true?'70px':'130px';//修改密码框的宽度
			var zoompathsrc = '<ctp:out name="zoomPath"/>';
			/**
             * 保存按钮
             * @version	 1.0
             * @since	 1.0
             * @author	kfzx-liukai           
             */
			function btnSave(){
				var _fnContext = "personal_modify.jsp" + "->btnSave()";
			    try {
			    	if(ctpForm.submitCheck()==false){ //表单校验
                   		return;
               	 	}
               	 	//安全改造：modify by kfzx-lvsx 20140906
               	 	if(ctpChangePassword.isChecked()){
               	 		//在密码控件里头获取password
               	 		//ctpOldPassword = document.frames["personal_password"].document.getElementById("old_pw_obj").CrpytPwd('C:\\Windows\\System32\\ICBC_CTP_1_00000_3DES_16');
               	 		//ctpPassword = document.frames["personal_password"].document.getElementById("new_pw_obj").CrpytPwd('C:\\Windows\\System32\\ICBC_CTP_1_00000_3DES_16');
						//ctpPassword2 = document.frames["personal_password"].document.getElementById("new_pw_obj2").CrpytPwd('C:\\Windows\\System32\\ICBC_CTP_1_00000_3DES_16');
                        ctpOldPassword = document.frames["personal_password"].document.getElementById("old_pw_obj").value;
                        ctpPassword = document.frames["personal_password"].document.getElementById("new_pw_obj").value;
                        ctpPassword2 = document.frames["personal_password"].document.getElementById("new_pw_obj2").value;
                        
						if(!ctpOldPassword){
							alert('<ctp:label key="input_user_old_pwd"/>');//请输入用户旧密码！
							return;
						}
						if(ctpOldPassword && !ctpPassword){
							alert('<ctp:label key="input_user_new_pwd"/>');//请输入用户新密码！
							return;
						}
						if(ctpOldPassword && ctpPassword && !ctpPassword2){
							alert('<ctp:label key="reinput_user_new_pwd"/>');//请输入用户新密码！
							return;
						}
						if(ctpOldPassword && ctpPassword && ctpPassword2 && ctpPassword !== ctpPassword2){
							alert('<ctp:label key="two_pwd_not_match"/>');//两次输入的密码不一致！
							return;
						}
                   	}
                    //ctpMSB.confirm({message:'<ctp:label key="user_modify_confirm"/>',handler:saveSubmit});
                    if(confirm('<ctp:label key="user_modify_confirm"/>')){//密码控件，只能用原生的方法
                    	saveSubmit();
                    }
			    }
			    catch (e) {
			        ctp.core.log.err(_fnContext, e.message);
			    }  
			}
			/**
             * 保存个人信息设置
             * @version	 1.0
             * @since	 1.0
             * @author	kfzx-liukai           
             */
			function saveSubmit(tp){
				var _fnContext = "personal_modify.jsp" + "->saveSubmit()";
			    try {
			    	//if(tp=='ok'){debugger;
			    		/*ctpOldPassword = 'Fuji_3610';
			    		ctpPassword = '111111';*/
				    	ctpForm.setHiddenValue('useroldPassword', ctpOldPassword);
				    	ctpForm.setHiddenValue('password', ctpPassword);
				    	ctpForm.submit();
					//}
			    }
			    catch (e) {
			        ctp.core.log.err(_fnContext, e.message);
			    }
			}
			/**
             * 上传头像按钮
             * @version	 1.0
             * @since	 1.0
             * @author	kfzx-liukai           
             */
			function btnZoom(){
				var _fnContext = "personal_modify.jsp" + "->btnZoom()";
			    try {
			    	document.personalZoom.submit();
			    	
			    	/*var srcPath = '<ctp:url href="personal.flowc" flowActionName="querypersonalzoom"/>';
			        ctpMSB.win({
			            message   :srcPath,
			            width     :700,
			            height    :450,
			            title     :'<ctp:label key="user_zoomimageup"/>',
			            handler   :func_handler,
			            maxBtn    :true,
			            minBtn    :true,
			            iframe    :true
			        });*/
			    }
			    catch (e) {
			        ctp.core.log.err(_fnContext, e.message);
			    }  
			}
			/**
             * 关闭上传头像页面回调函数
             * @version	 1.0
             * @since	 1.0
             * @author	kfzx-liukai           
             */
             /*
			function func_handler(retObj){
				if(retObj == 'close')   //默认点击关闭按钮回带'close'
				{
					var data = ctp.data.getJSON('<ctp:url href="personal.flowc" flowActionName="queryzoom"/>');
					alert(data.out_flag);
					ctpMSB.close();
				}
			}*/
			/**
             * 点击修改密码
             * @version	 1.0
             * @since	 1.0
             * @author	kfzx-liukai           
             */
			function changepwd(){
				var _fnContext = "personal_modify.jsp" + "->changepwd()";
			    try {
				    //安全改造 modify by kfzx-lvsx 20140906
				    if(ctpChangePassword.isChecked()){
				    	$("#personal_password").attr("src", iframeSrc);
				    }else{
				    	$("#personal_password").attr("src", "");
				    }
			    }
			    catch (e) {
			        ctp.core.log.err(_fnContext, e.message);
			    }  
			}
			/**
             * 保存个人信息成功后执行
             * @version	 1.0
             * @since	 1.0
             * @author	kfzx-liukai           
             */
			function personalFormSucc(data){
				var _fnContext = "personal_modify.jsp" + "->personalFormSucc()";
			    try {
			    	if(data[0].out_flag=='0' || data[0].out_flag=='3'){
		    			//ctpMSB.succeed({title:'<ctp:label key="modify_result"/>',message:'<ctp:label key="modify_user_success"/>'});
		    			//统一风格，用原生
		    			alert('<ctp:label key="modify_user_success"/>');
		    			ctpChangePassword.setChecked(false);
		    			changepwd();
		    			ctpGroupbox2.collapse();
			    	}
		    		else{
						//ctpMSB.error({title:'<ctp:label key="modify_result"/>',message:data[0].errorMsg});
						//统一风格，用原生
						alert(data[0].errorMsg);
					}
					//因为页面不刷新，所以要清空几个密码控件的变量
			    	ctpOldPassword = '';
		    		ctpPassword = '';
		    		ctpPassword2 = '';
			    }
			    catch (e) {
			        ctp.core.log.err(_fnContext, e.message);
			    }  
			}
		</script>
		<script type='text/javascript' kind='notUi'>
			//================================非UI组件定义片段==========================================================
			//验证框架
			var ctpValidator  = new ctp.validator({
               	id: 'validator',
               	container: $('body')
            });
		</script>
		<script type='text/javascript' kind='ui'>
			//================================UI组件定义片段============================================================
			/**
             * 创建UI组件
             * @version	 1.0
             * @since	 1.0
             * @author	kfzx-liukai           
             */		    
		    function initUI(){
		    	var _mContext = "personal_modify.jsp -> initUI()";
           	 	try {

	       	 		//$('#form1').parent().appendTo(ctpBorderlayout.panes.center);
           	 		//创建工具条
           	 		ctpToolbar=new ctp.ui.toolbar({
						id : 'toolBar',			
		            	leftItems :[
		    		        {
								id : "_toolbar_button_confirm",
				            	type : 'button',
				            	text : '<ctp:label key="confirm"/>',
				           		icon : 'apply',
				            	onClick : btnSave
		    		        }]		   
				    });
           	 		//创建表单对象
	           	 	ctpId = new ctp.ui.label({id:'ctpId',name:'id',width: '100%',text:'<ctp:out name="sessCtx.user.id" />'});
		    		ctpName = new ctp.ui.textfield({id:'ctpName',name:'userName',width: '100%',value:'<ctp:out name="userName" defaultValue="" />',validate:'rules[required,length[0,50],notValidInputText]'});
		    		ctpDescription = new ctp.ui.textarea({id:'ctpDescription',name:"userDesc",width: '100%',rows:3,value:'<ctp:out name="userDesc" defaultValue="" />',validate:'rules[length[0,500],notValidInputText]'});
		    		ctpPhoneNo = new ctp.ui.textfield({id:'ctpPhoneNo',name:"phoneNo",width: '100%',value:'<ctp:out name="phoneNo" defaultValue="" />',validate:'rules[length[0,20],telephone,notValidInputText]'});
		    		ctpEmail = new ctp.ui.textfield({id:'ctpEmail',name:"userEmail",width: '100%',value:'<ctp:out name="userEmail" defaultValue="" />',validate:'rules[email,length[0,50],notValidInputText1]'});
		    		ctpAddress = new ctp.ui.textfield({id:'ctpAddress',name:"userAddress",width: '100%',value:'<ctp:out name="userAddress" defaultValue="" />',validate:'rules[length[0,500],notValidInputText]'});
		    		ctpPostcode = new ctp.ui.textfield({id:"ctpPostcode",name:"userPostcode",width: '100%',value:'<ctp:out name="userPostcode" defaultValue="" />',validate:'rules[zipcode,notValidInputText]'});
		    		ctpChangePassword = new ctp.ui.checkbox({id:'ctpChangePassword',width: widthPassword,label:'<ctp:label key="modify_pwd"/>',checked: false,onChange:changepwd});
		    		//ctpOldPassword = new ctp.ui.textfield({id:'ctpOldPassword',name:'useroldPassword',width: '100%',type:'password',validate:'rules[length[0,15],required,notValidInputText]'});
		    		//ctpPassword = new ctp.ui.textfield({id:'ctpPassword',name:'password',width: '100%',type:'password',validate:'rules[length[0,15],required,notValidInputText]'});
		    		//ctpPassword2 = new ctp.ui.textfield({id:'ctpPassword2',name:'password2',width: '100%',type:'password',validate:'rules[length[0,15],confirm[ctpPassword],required,notValidInputText]'});
					if(zoompathsrc){
						ctpImage = new ctp.ui.image({id:'ctpImage',name:'image',width: '80px',height:'100px',imgSrc:$('#fullFilePathZoom').val()});
					}else{
						ctpImage = new ctp.ui.image({id:'ctpImage',name:'image',width: '80px',height:'100px',imgSrc:''});
					}
		    		
		    		ctpUploadImage = new ctp.ui.button({id:'ctpUploadImage',width: '80px',text:'<ctp:label key="user_zoomimageup"/>',onClick:btnZoom});
					//创建布局
		    		ctpGridlayout1 = new ctp.ui.gridlayout({
	                    id: 'gridlayout1',
						cols: 2,
						colSpace: 30,
						defaults: {label:{width:'100px'}},
						items: [
							[{label:{id:'ctpIdLabel',text:'<ctp:label key="user.userId.label"/><span style="color:red;">*</span>:'},element: ctpId},{label:{id:'ctpNameLabel',text:'<ctp:label key="user.userName.label"/>:<span style="color:red;">*</span>'},element: ctpName}],
							[{label:{id:'ctpPhoneNoLabel',text:'<ctp:label key="user.userPhone.label"/>:'},element: ctpPhoneNo},{label:{id:'ctpEmailLabel',text:'<ctp:label key="user.userEmail.label"/>:'},element: ctpEmail}],
							[{label:{id:'ctpAddressLabel',text:'<ctp:label key="user.userAddress.label"/>:'},element: ctpAddress},{label:{id:'ctpPostcodeLabel',text:'<ctp:label key="user.userPostcode.label"/>:'},element: ctpPostcode}],
							[{colspan: 2,label:{id:'ctpDescriptionLabel',text:'<ctp:label key="user.userDes.label"/>:'},element: ctpDescription}]
						]
	                });
		    		ctpGridlayout2 = new ctp.ui.gridlayout({
	                    id: 'gridlayout2',
						cols: 2,
						colSpace: 30,
						defaults: {label:{width:'100px'}},
						items: [
							[{label:{id:'ctpOldPasswordLabel',text:'<ctp:label key="user.useroldPassword.label"/><span style="color:red;">*</span>:'},element: ctpOldPassword},{label:{id:'ctpPasswordLabel',text:'<ctp:label key="user.userPassword.label"/><span style="color:red;">*</span>:'},element: ctpPassword}],
							[{label:{id:'ctpPassword2Label',text:'<ctp:label key="user.userPassword2.label"/><span style="color:red;">*</span>:'},element: ctpPassword2}]
						]
	                });
		    		ctpGridlayout4 = new ctp.ui.gridlayout({
	                    id: 'gridlayout4',
						cols: 1,
						colSpace: 30,
						defaults: {label:{width:'100px'}},
						items: [
							[{element: ctpImage}],[{element: ctpUploadImage}]
						]
	                });
		    		ctpGridlayout3 = new ctp.ui.gridlayout({
	                    id: 'gridlayout3',
						align: 'center',
						cols: 7,
						colSpace: 30,
						defaults: {label:{width:'100px'}},
						items: [
							[{colspan: 6,element: ctpGridlayout1},{element: ctpGridlayout4}]
						]
	                });
		    		//创建Groupbox1
		    		ctpGroupbox1 = new ctp.ui.groupbox({
				  		id: 'groupbox1',	
				  		align:'center',			
						title:'<ctp:label key="personal_info"/>',
						items:[ctpGridlayout3]			   
				    });

	    			ctpPwdInfoPanel = new ctp.ui.panel({
		    			id: 'ctpPwdInfoPanel',
		    			style: 'none',
		    			width: '100%',
		    			height: '120px',
		    			contentPadding: '0px',
		    			bodyPadding: '0px',
		    			visible: 'hidden',
		    			html: '<iframe id="personal_password" marginheight="0" marginwidth="0" width="100%" height="100%" frameborder="0" scrolling="no" src=""></iframe>'
		    		});
				    
		    		ctpGroupbox2 = new ctp.ui.groupbox({
				  		id: 'groupbox2',	
				  		align:'center',		
						title:'',
						icon:ctpChangePassword,
						//items:[ctpGridlayout2]
						items: [ctpPwdInfoPanel]			   
				    });
			        //创建Form
			        ctpForm = new ctp.form({
		            	id: 'personalSave',
		                height: '100%', //高度
	                    items: [ctpGroupbox1,ctpGroupbox2],
	                    validator:ctpValidator,
    				    postType:'ajax',			        
    				    ajaxPostParam:{success: personalFormSucc}
		            });
			        //创建Panel
			        ctpPanel = new ctp.ui.panel({
						id: 'panel1',
			            title: '<ctp:label key="user_detail_modify"/>',
			           	items:[ctpForm],
			           	toolbar:ctpToolbar,
			           	toolbarPos:'innertop'
			        });
	       	 		//创建页面框架布局器
	       	 		ctpBorderlayout = new ctp.ui.borderlayout({
	                    type: "1C",
	                    center__scrollable:false,
	                    center__items:[ctpPanel],
	                    renderTo:'body'
	                });
			        ctpGroupbox2.collapse();
	                changepwd();
	                if('true'=='<ctp:out name="servCtx.enableSSIC"/>'){
	                	ctpGroupbox2.hide();
		            }
	                
	               // var data = ctp.data.getJSON('<ctp:url href="personal.flowc" flowActionName="queryzoom"/>');
           	 	}
	        	catch (e) {
	            	ctp.core.log.err(_mContext, e.message);
	            }
			}
        </script>
	</head>
	<body onload='initUI()'>
		<ctp:form name="personalSave" method="post" action="personal.flowc" flowActionName="updatePersonalDetail">
			<input type="hidden" name="password" value=""/>
			<input type="hidden" name="useroldPassword" value=""/>
		</ctp:form>
		<ctp:form name="personalZoom" method="post" action="personal.flowc" flowActionName="querypersonalzoom">
			<input type='hidden' id='fullFilePathZoom' value='<ctp:out name="fullPath"/><ctp:out name="zoomPath"/>' />
		</ctp:form>
	</body>
</html>

<%--
	date        :
	modifyReason:
--%>